﻿#If NETFX_CORE Then

Imports Windows.System.Threading

Namespace Global.System.Threading.Timers

    Public Class Timer

        Public Property Interval() As Integer

        Public Property Enable() As Boolean
            Get
                Return Me.m_enable
            End Get
            Set(value As Boolean)
                Me.m_enable = value
                If value = True Then
                    Me.m_timer = ThreadPoolTimer.CreatePeriodicTimer(AddressOf Me.TimerElapsedHandler, New TimeSpan(Me.Interval))
                Else
                    If Me.m_timer IsNot Nothing Then
                        Me.m_timer.Cancel()
                    End If
                End If
            End Set
        End Property

        Public Event Elapsed(ByVal sender As Object, ByVal e As EventArgs)

        Private m_timer As ThreadPoolTimer
        Private m_enable As Boolean = False

        Public Sub New()
            Me.Enable = False
            Me.Interval = 100
        End Sub

        Public Sub TimerElapsedHandler(timer As ThreadPoolTimer)
            RaiseEvent Elapsed(Me, New EventArgs())
        End Sub

    End Class

End Namespace

#End If